﻿package {
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.display.Stage;
	import flash.display.StageScaleMode;
	import flash.events.*;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	public class photoCaseDoc extends MovieClip {
		public function photoCaseDoc() {
			var obs:OverBtnSound=new OverBtnSound();
			var ls:LoadedSound=new LoadedSound();
			var backS:BackSound=new BackSound();
			var showCase:ZoomContainer=new ZoomContainer();
			var container:Sprite=new Sprite();
			var btnMaskLayer:BtnMaskLayer=new BtnMaskLayer();
			var btnContainer:Sprite=new Sprite();
			var btnCover:Shape=new Shape();
			var loadMc:LoadMc=new LoadMc();
			var me:aboutme=new aboutme();
			var tweenBtn:Tween;
			var tweenMeX:Tween;
			var tweenMeY:Tween;


			var btn_Ary:Array=new Array();
			var xmlRequest:URLRequest=new URLRequest("photoUrl.xml");
			var xmlLoader:URLLoader=new URLLoader();
			var urlXml:XML;
			var btnUrlList:XMLList;
			var btnUrl:Array=new Array();
			var showUrl:Array=new Array();

			const clearance:uint=5;
			const dynamicMaskW:uint=100;
			const speedControl:uint=10;

			stage.scaleMode = StageScaleMode.NO_SCALE;
			backS.play(0,100);
			addChild(showCase);
			showCase.x=400;
			showCase.y=300;
			addChild(container);
			container.x=400;
			container.y=500;
			container.addChild(btnContainer);
			container.addChild(btnMaskLayer);
			container.addChild(btnCover);
			btnContainer.mask=btnMaskLayer;


			addChild(loadMc);
			loadMc.x=400;
			loadMc.y=300;
			loadMc.visible=false;
			showCase.addChild(me);
			me.x=-30;
			with (btnCover) {
				graphics.beginFill(0xffffff,0);
				graphics.drawRect(-btnMaskLayer.width/2,-btnMaskLayer.height/2,btnMaskLayer.width,btnMaskLayer.height);
				graphics.endFill();
			}

			showCase.load_zoom("/images/p1.jpg");
			xmlLoader.load(xmlRequest);
			xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);
			function xmlLoaded(evt:Event) {

				urlXml=new XML(evt.target.data);
				btnUrlList=urlXml.btnPhoto;
				const photoNum:uint=btnUrlList.length();

				for (var i:uint; i<photoNum; i++) {

					btnUrl[i]=(urlXml.btnPhoto.@url[i]).toString();
					showUrl[i]=(urlXml.showPhoto.@url[i]).toString();
					btn_Ary[i]=new DynamicMask(3,1.4,0x444444,0.6,0xffffff,0.6,0xffffff,0.4,btnUrl[i]);
					btn_Ary[i].orderNum=i;
					btnContainer.addChild(btn_Ary[i]);
					btn_Ary[i].x=i*(dynamicMaskW+clearance)-(photoNum-1)*(dynamicMaskW+clearance)/2;
					btn_Ary[i].addEventListener(MouseEvent.CLICK,btnClick);
					btn_Ary[i].addEventListener(MouseEvent.ROLL_OVER,btnOver);
					function btnClick(evt:Event) {
						showCase.unloadPhoto();
						showCase.load_zoom(showUrl[evt.currentTarget.orderNum]);
					}
					function btnOver(evt:Event) {
						//语句
					}
				}
			}
			container.addEventListener(MouseEvent.ROLL_OVER,overContainer);
			container.addEventListener(MouseEvent.ROLL_OUT,outContainer);
			function overContainer(evt:Event) {
				obs.play();
				evt.currentTarget.addEventListener(Event.ENTER_FRAME,entFrame);

			}
			function outContainer(evt:Event) {

				tweenBtn=new Tween(btnContainer,"x",Regular.easeOut,btnContainer.x,0,1,true);
				evt.currentTarget.removeEventListener(Event.ENTER_FRAME,entFrame);

			}
			function entFrame(evt:Event) {
				if ((btnContainer.x<220 && evt.currentTarget.mouseX<0)||(btnContainer.x>-220 && evt.currentTarget.mouseX>0)) {
					btnContainer.x+=-evt.currentTarget.mouseX/speedControl;
				}
			}
			showCase.addEventListener("LOAD_BEGIN",loadBegin);
			showCase.addEventListener("ZOOM_END",zoomEnd);
			function loadBegin(evt:Event) {
				loadMc.visible=true;
				loadMc.play();
			}
			function zoomEnd(evt:Event) {
				ls.play();
				loadMc.visible=false;
				loadMc.stop();
				tweenMeX=new Tween(me,"x",Regular.easeIn,me.x,Math.floor(-3*(showCase.photoW/10)),0.5,true);
				tweenMeY=new Tween(me,"y",Regular.easeIn,me.y,-Math.floor(showCase.photoH/2),0.5,true);
			}

			black.visible=false;
			brown.visible=false;
			red.visible=true;
			blue.visible=false;
			b1.addEventListener(MouseEvent.CLICK,selectBlack);
			b2.addEventListener(MouseEvent.CLICK,selectBrown);
			b3.addEventListener(MouseEvent.CLICK,selectRed);
			b4.addEventListener(MouseEvent.CLICK,selectBlue);
			b1.buttonMode=true;
			b3.buttonMode=true;
			b2.buttonMode=true;
			b4.buttonMode=true;

			function selectBlack(evt:Event) {
				black.visible=true;
				brown.visible=false;
				red.visible=false;
				blue.visible=false;
			}
			function selectBrown(evt:Event) {
				black.visible=false;
				brown.visible=true;
				red.visible=false;
				blue.visible=false;
			}
			function selectRed(evt:Event) {
				black.visible=false;
				brown.visible=false;
				red.visible=true;
				blue.visible=false;
			}
			function selectBlue(evt:Event) {
				black.visible=false;
				brown.visible=false;
				red.visible=false;
				blue.visible=true;
			}
		}
	}
}